home *** CD-ROM | disk | FTP | other *** search
/ The AGA Experience 3 / AGA Experience Volume 3 (1997)(NFA - SAdENESS)[!].iso / software / utilities / graphics / raylab / source / pic.c < prev    next >
C/C++ Source or Header  |  1996-07-26  |  3KB  |  126 lines

  1. /*
  2.     name:    pic.c
  3.  
  4.     Multiple picture formats support
  5.     --------------------------------
  6.  
  7.  
  8.     This source-code is part of the RayLab 1.1 package, and it is provided
  9.     for your compiling pleasure.  You may use it, change it, re-compile it
  10.     etc., as long as nobody else but you receive the changes/compilations
  11.     that you have made!
  12.  
  13.     You may not use any part(s) of this source-code for your own productions
  14.     without the permission from the author of RayLab. Please read the legal
  15.     information found in the users documentation for RayLab for more details.
  16.  
  17. */
  18.  
  19. #include <stdlib.h>
  20.  
  21. #include  "defs.h"
  22. #include  "extern.h"
  23.  
  24.  
  25. /* ---------------------------------------------------------------------
  26.    WritePicHeader()
  27.    --------------------------------------------------------------------- */
  28.  
  29. void WritePicHeader(FILE *f, long width, long height)
  30. {
  31.     if(OutputFormat==FORMAT_TGA)
  32.         WriteTgaHeader(f,width,height);
  33.     else if(OutputFormat==FORMAT_IFF)
  34.         WriteIffHeader(f,width,height);
  35.     else if(OutputFormat==FORMAT_PPM)
  36.         WritePpmHeader(f,width,height);
  37. }
  38.  
  39.  
  40. /* ---------------------------------------------------------------------
  41.    WritePicLine()
  42.    --------------------------------------------------------------------- */
  43.  
  44. void WritePicLine(FILE *f, long width)
  45. {
  46.     if(OutputFormat==FORMAT_TGA)
  47.         WriteTgaLine(f,width);
  48.     else if(OutputFormat==FORMAT_IFF)
  49.         WriteIffLine(f,width);
  50.     else if(OutputFormat==FORMAT_PPM)
  51.         WritePpmLine(f,width);
  52.     RenderedLines++;        /* Count the amount of written lines */
  53. }
  54.  
  55.  
  56. /* ---------------------------------------------------------------------
  57.    CleanupPic()
  58.    --------------------------------------------------------------------- */
  59.  
  60. void CleanupPic(FILE *f)
  61. {
  62.     if(OutputFormat==FORMAT_TGA)
  63.         CleanupTga(f);
  64.     else if(OutputFormat==FORMAT_IFF)
  65.         CleanupIff(f);
  66.     else if(OutputFormat==FORMAT_PPM)
  67.         CleanupPpm(f);
  68. }
  69.  
  70.  
  71.  
  72. /* ---------------------------------------------------------------------
  73.    ReadPicHeader()
  74.    --------------------------------------------------------------------- */
  75.  
  76. void ReadPicHeader(char *Name, int Format, FILE **f, long *width, long *height)
  77. {
  78.     if((*f=fopen(Name,"rb"))==NULL) {
  79.         fprintf(textoutput,"\nError: Could not open image file \"%s\"\n",Name);
  80.         *width=*height=-1;
  81.     }
  82.     else {
  83.         if(Format==FORMAT_TGA)
  84.         ReadTgaHeader(*f,width,height);
  85.         else if(Format==FORMAT_IFF)
  86.         ReadIffHeader(*f,width,height);
  87.         else if(Format==FORMAT_PPM)
  88.         ReadPpmHeader(*f,width,height);
  89.     }
  90. }
  91.  
  92.  
  93. /* ---------------------------------------------------------------------
  94.    ReadImage()
  95.    --------------------------------------------------------------------- */
  96.  
  97. short ReadImage(int *ImageNum,int Format, FILE *f, long width, long height)
  98. {
  99.     short    ImageType;
  100.  
  101.     if(Format==FORMAT_TGA)
  102.         ImageType=ReadTgaImage(ImageNum,f,width,height);
  103.     else if(Format==FORMAT_IFF)
  104.         ImageType=ReadIffImage(ImageNum,f,width,height);
  105.     else if(Format==FORMAT_PPM)
  106.         ImageType=ReadPpmImage(ImageNum,f,width,height);
  107.     else {
  108.         ImageType=IMG_NONE;
  109.         *ImageNum=0;
  110.     }
  111.  
  112.     switch(ImageType) {
  113.         case IMG_24BIT:
  114.         ClearTransform(&Img24Array[*ImageNum]->Transform);
  115.         break;
  116.         case IMG_8BIT:
  117.         ClearTransform(&Img8Array[*ImageNum]->Transform);
  118.         break;
  119.         case IMG_NONE:
  120.         default:
  121.         break;
  122.     }
  123.  
  124.     return(ImageType);
  125. }
  126.